package com.sc.nft.service.impl;

import com.sc.nft.dao.RewardAllocationDao;
import com.sc.nft.entity.RewardAllocation;
import com.sc.nft.entity.dto.ActivityAwardSaveDTO;
import com.sc.nft.enums.PrizeDrawActivityTypeEnum;
import com.sc.nft.service.ActivityAwardService;
import com.sc.nft.service.RewardAllocationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
* @author 张超
* @description 针对表【sc_reward_allocation(签到活动奖励配置表)】的数据库操作Service实现
* @createDate 2024-06-04 13:29:51
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class RewardAllocationServiceImpl implements RewardAllocationService {

    private final RewardAllocationDao rewardAllocationDao;
    private final ActivityAwardService activityAwardService;

    @Override
    public void save(List<ActivityAwardSaveDTO> activityAwards, Long activityBasicsId, PrizeDrawActivityTypeEnum type) {

        ArrayList<RewardAllocation> rewardAllocations = new ArrayList<>();
        activityAwards.forEach(activityAwardSaveDTO -> {
            RewardAllocation rewardAllocation = new RewardAllocation();
            rewardAllocation.setActivityBasicsId(activityBasicsId);
            rewardAllocation.setSignInDay(activityAwardSaveDTO.getSignInDay());
            rewardAllocation.setReceiveLimit(activityAwardSaveDTO.getReceiveLimit());
            rewardAllocation.setSignInType(type.getCode());
            rewardAllocations.add(rewardAllocation);
            rewardAllocation.insert();
            //新增奖励信息
            activityAwardService.saveActivityAward(rewardAllocation.getId(),activityAwardSaveDTO.getActivityAwardSaveDetails(),activityBasicsId);
        });
    }

    /**
     * 根据活动Id查询活动配置内容
     * @param activityId
     * @return
     */
    @Override
    public List<RewardAllocation> getRewardByActivityId(Long activityId) {
        return rewardAllocationDao.getRewardByActivityId(activityId);
    }

    /**
     * 获取签到奖励周期配置领取上限
     * @param rewardByActivityId
     * @return
     */
    @Override
    public RewardAllocation getRewardAllocationById(Long rewardByActivityId) {
        return rewardAllocationDao.getById(rewardByActivityId);
    }
}




